package org.example.simplemanagementsystem.service.impl;


import org.example.simplemanagementsystem.mapper.DeptMapper;
import org.example.simplemanagementsystem.mapper.EmpMapper;
import org.example.simplemanagementsystem.pojo.Dept;
import org.example.simplemanagementsystem.pojo.Emp;
import org.example.simplemanagementsystem.service.DeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class DeptServiceImpl implements DeptService {
    @Autowired
    private DeptMapper deptMapper;
    @Autowired
    private EmpMapper empMapper;

    @Override
    public List<Dept> findAll() {
        return deptMapper.findAll();
    }

    @Override
    public int deleteById(Integer id) {
        // 判断员工表里是否还存在这个部门id
        if  (empMapper.getClazzId(id) != null) {
            return -1;
        }
        return deptMapper.deleteById(id);
    }

    @Override
    public void add(Dept dept) {
        deptMapper.add(dept);
    }

    @Override
    public Dept getInfo(Integer id) {
        return deptMapper.getInfo(id);
    }

    @Override
    public void update(Dept dept) {
        dept.setUpdateTime(LocalDateTime.now());
        deptMapper.update(dept);
    }
}
